package com.lht.admin.conf;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * <p>
 *
 * @author cs12110 create at 2020-02-02 23:38
 * <p>
 * @since 1.0.0
 */
@Component
@Data
@PropertySource(value={"classpath:oss.properties"})
public class AliyunOssConf {

    @Value("${oss.endpoint}")
    private String endpoint;
    @Value("${oss.access.key.id}")
    private String id;
    @Value("${oss.access.key.secret}")
    private String secret;
    @Value("${oss.bucket}")
    private String bucket;
    @Value("${oss.visit.site}")
    private String visitSite;


    public static void main(String[] args) {
        String endpoint = "oss-cn-beijing.aliyuncs.com";
        String bucket = "oss-beemark-lht";
        String id = "LTAI4Fg5faJ8Faz93mrmFQ4r";
        String secret = "vTxcXoExPjNnKto6KhdfEIirV3jYjV";
        String visitSite = "https://oss-beemark-lht.oss-cn-beijing.aliyuncs.com";

        String fileName = System.currentTimeMillis() + ".jpg";


        OSS ossClient = new OSSClientBuilder().build(endpoint, id, secret);

        ossClient.putObject(bucket, fileName, new File("/opt/paper/forest.jpg"));
        ossClient.shutdown();
        System.out.println("上传图片完成！");
        System.out.println("url: " + visitSite + "/" + fileName);

    }

}
